
import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseAd from "../../core/base/BaseAd";
import { ADName, SDKLogicState, SDKState } from "../../SDKDefine";

@registerClass('CocosBannerAd')
export default class CocosBannerAd extends BaseAd {

    hide(): void {
        throw new Error("Method not implemented.");
    }
    load(): void {
        throw new Error("Method not implemented.");
    }
    show(): void {
        throw new Error("Method not implemented.");
    }


    onError(err: any) {
        this.setState(SDKState.loadFail)
    }

    create() {
        if (!this.ad) {
            this.ad = this.sdk.createBannerAd(ADName.banner, this.adUnitID, 2);
            this.ad.onLoad(this.onLoad.bind(this))
            this.ad.onError(this.onError.bind(this))
        }

    }
    onLoad() {
        this.setState(SDKState.loadSucess)
    }
    destroy(): void {
        console.log(' banner destroy', this.ad)
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.destroy();
            this.ad = null;
        }
    }





}
